<template>
  <div
    class="edge-attr-container"
    :style="{
      color: themeStyle[theme].textColor1
    }"
  >
    <!-- 边属性标题 -->
    <div
      class="title"
      :style="{
        borderBottom: `1px solid ${themeStyle[theme].borderColor1}`
      }"
    >
      <span style="color: #0087dc">{{ '节点属性' }}</span>
      <div class="icon" :class="Edgedata.lock ? 'lockIcon' : ''">
        <template v-if="Edgedata.lock">
          <LockOutlined @click="switchLock" />
        </template>
        <template v-else>
          <UnlockOutlined @click="switchLock" />
        </template>
      </div>
    </div>

    <div class="attr-content">
      <size-transition>
        <Form
          :model="Edgedata"
          :label-col="{ span: 8 }"
          :wrapper-col="{ span: 16 }"
          :label-align="'left'"
          :disabled="Edgedata.lock"
          autocomplete="off"
        >
          <!-- 启用搬运流 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '启用搬运' }}</span
              >
            </template>
            <Switch
              v-model:checked="Edgedata.simData.isTransport"
              size="small"
              checked-children="开"
              un-checked-children="关"
            />
          </FormItem>

          <FormItem v-if="Edgedata.simData.isTransport">
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '搬运节点' }}</span
              >
            </template>
            <Select
              v-model:value="Edgedata.simData.transportId"
              size="small"
              @change="handleChange"
            >
              <SelectOption
                v-for="item in transportList"
                :key="item.value"
                :value="item.value"
                :label="item.label"
              >
                <span style="color: #666; font-size: 13px">
                  {{ item.label }}
                </span>
              </SelectOption>
            </Select>
          </FormItem>
        </Form>
      </size-transition>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useStyleStore } from '@renderer/store/globalStyle/style'
import { storeToRefs } from 'pinia'
import { Edgedata, handleChange } from './edgeProTemHook'
import { onUnmounted, ref, watch } from 'vue'
import { LockOutlined, UnlockOutlined } from '@ant-design/icons-vue'
import SizeTransition from '@renderer/components/sizeTransition/SizeTransition.vue'
import { Form, FormItem, Input, Select, SelectOption, Popover, Switch } from 'ant-design-vue'

const globalStyleStore = useStyleStore()
const { theme, themeStyle } = storeToRefs(globalStyleStore)

const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
    required: false
  }
})
Edgedata.value = props.data
watch(
  () => props.data,
  (val) => {
    // handleChange()
    Edgedata.value = props.data
  },
  {
    deep: true
  }
)
onUnmounted(() => {
  handleChange()
})

const switchLock = (): void => {
  Edgedata.value.lock = !Edgedata.value.lock
  handleChange()
}

const transportList = ref<{ label: string; value: string }[]>([])
//获取搬运流设备
const getTransportList = async () => {
  transportList.value = []
  const res = await window.api.handleCanvasData('getCanvas', 'property', false, [])
  const nodes = res.nodes
  nodes.forEach((item: any) => {
    if (item.shape === 'transport-node') {
      transportList.value.push({
        label: item.name,
        value: item.id
      })
    }
  })
}
getTransportList()
</script>

<style scoped lang="scss">
.edge-attr-container {
  width: 100%;
  height: 100%;
  font-size: $font-size-medium;

  .title {
    padding: 3px 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;

    .icon {
      margin-right: 10px;
      cursor: pointer;
      width: 25px;
      height: 25px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 5px;
      color: #7e7e7e;
    }
    .lockIcon {
      background-color: $icon-active-bgColor;
      color: $icon-active-color;
    }
  }
  .attr-content {
    padding: 5px 3px 5px 6px;
    height: calc(100% - 60px);
    user-select: none;
    :deep(.ant-form-item) {
      margin-bottom: 0px;
    }

    :deep(.basic-info-item-prefix) {
      width: 16px;
      font-size: $font-size-small;
    }
    :deep(.ant-select-selector) {
      border-radius: 0px;
    }

    .content-item-label {
      font-size: $font-size-small;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
</style>
